﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Admin
{
    public partial class Message : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BookBinder();
               
            }
        }


        protected void BookBinder()
        {
            int PageIndex = Pager.CurrentPageIndex;
            int PageSize = Pager.PageSize;
            int RecordCount = 0;
            rpt.DataSource = bllBook.GetAllList(PageIndex, PageSize, out RecordCount);
            rpt.DataBind();
            Pager.RecordCount = RecordCount;
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.BookBinder();
        }


        /// <summary>
        /// 批量审核通过
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOk_Click(object sender, EventArgs e)
        {
            string bID = string.Empty;
            foreach (RepeaterItem Item in rpt.Items)
            {
                Literal lbl = (Literal)Item.FindControl("lblbID");
                CheckBox chk = (CheckBox)Item.FindControl("chkIndex");

                if (chk.Checked)
                {
                    bID += lbl.Text + ",";
                }
            }
            bID = bID.TrimEnd(',');
            if (!string.IsNullOrEmpty(bID))
            {
                bllBook.UpdateIsPub(bID, true);
                JScript.AlertAndRedirect("批量操作成功", "Message.aspx");
            }
        }

        /// <summary>
        /// 批量审核取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNo_Click(object sender, EventArgs e)
        {
            string bID = string.Empty;
            foreach (RepeaterItem Item in rpt.Items)
            {
                Literal lbl = (Literal)Item.FindControl("lblbID");
                CheckBox chk = (CheckBox)Item.FindControl("chkIndex");

                if (chk.Checked)
                {
                    bID += lbl.Text + ",";
                }
            }
            bID = bID.TrimEnd(',');
            if (!string.IsNullOrEmpty(bID))
            {
                bllBook.UpdateIsPub(bID, false);
                JScript.AlertAndRedirect("批量操作成功", "Message.aspx");
            }

        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            string bID = string.Empty;
            foreach (RepeaterItem Item in rpt.Items)
            {
                Literal lbl = (Literal)Item.FindControl("lblbID");
                CheckBox chk = (CheckBox)Item.FindControl("chkIndex");

                if (chk.Checked)
                {
                    bID += lbl.Text + ",";
                }
            }
            bID = bID.TrimEnd(',');
            if (!string.IsNullOrEmpty(bID))
            {
                bllBook.DeleteAll(bID);
                JScript.AlertAndRedirect("批量删除成功", "Message.aspx");
            }
        }
    }
}